package com.ruoyi.message.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.message.domain.GymInfo;
import com.ruoyi.message.service.IGymInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门店Controller
 * 
 * @author zsc
 * @date 2023-03-29
 */
@RestController
@RequestMapping("/message/gym")
public class GymInfoController extends BaseController {
    @Autowired
    private IGymInfoService gymInfoService;

    /**
     * 查询门店列表
     */
    @PreAuthorize("@ss.hasPermi('message:gym:list')")
    @GetMapping("/list")
    public TableDataInfo list(GymInfo gymInfo) {
        startPage();
        List<GymInfo> list = gymInfoService.selectGymInfoList(gymInfo);
        return getDataTable(list);
    }

    /**
     * 导出门店列表
     */
    @PreAuthorize("@ss.hasPermi('message:gym:export')")
    @Log(title = "门店", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GymInfo gymInfo) {
        List<GymInfo> list = gymInfoService.selectGymInfoList(gymInfo);
        ExcelUtil<GymInfo> util = new ExcelUtil<GymInfo>(GymInfo.class);
        util.exportExcel(response, list, "门店数据");
    }

    /**
     * 获取门店详细信息
     */
    @PreAuthorize("@ss.hasPermi('message:gym:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(gymInfoService.selectGymInfoById(id));
    }

    /**
     * 新增门店
     */
    @PreAuthorize("@ss.hasPermi('message:gym:add')")
    @Log(title = "门店", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GymInfo gymInfo) {
        return toAjax(gymInfoService.insertGymInfo(gymInfo));
    }

    /**
     * 修改门店
     */
    @PreAuthorize("@ss.hasPermi('message:gym:edit')")
    @Log(title = "门店", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GymInfo gymInfo) {
        return toAjax(gymInfoService.updateGymInfo(gymInfo));
    }

    /**
     * 删除门店
     */
    @PreAuthorize("@ss.hasPermi('message:gym:remove')")
    @Log(title = "门店", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(gymInfoService.deleteGymInfoByIds(ids));
    }
}
